<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - May 6, 2013
 */
require 'foo.config.php';

if ($_REQUEST['action'] == 'modifySI') {
    $siid = $_GET['siid'];
    $session_id = session_id();
    $sess_cusID = $_SESSION['user']['id'];

    $query = "UPDATE stockin SET session_id = '" . $sess_cusID . "', junkentry = '1' WHERE stockin_id = '" . $siid . "' AND session_id = '" . $session_id . "' ";
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }

    $rows = selectAllWhereAA('stockin', 'session_id', $session_id, $db);

    echo "<table class=\"row-fluid table table-striped table-bordered\">";
            echo "<tr>";
            echo "<th>" . $optionsIcons['optionIcon'] . "</th>";
            echo "<th>" . $stock_in['serialno'] . "</th>";
            echo "<th>" . $stock_in['project_id'] . "</th>";
            echo "<th>" . $stock_in['productid'] . "</th>";
            echo "<th>" . $stock_in['description'] . "</th>";
            echo "<th>" . $stock_in['revisionstate'] . "</th>";
            echo "<th>" . $stock_in['shiptype'] . "</th>";
            echo "<th>" . $stock_in['in_quantity'] . "</th>";
            echo "<th>" . $stock_in['uom'] . "</th>";
            echo "<th>" . $stock_in['invoicenumber'] . "</th>";
            echo "<th>" . $stock_in['shipid'] . "</th>";
            echo "<th>" . $stock_in['mawb'] . "</th>";
            echo "<th>" . $stock_in['hawb'] . "</th>";
            echo "<th>" . $stock_in['receiveddate'] . "</th>";
            echo "<th>" . $stock_in['shipfrom'] . "</th>";
            echo "<th>" . $stock_in['boxno'] . "</th>";
            echo "<th>" . $stock_in['rma'] . "</th>";
            echo "<th>" . $stock_in['warehouse_name'] . "</th>";
            echo "<th>" . $stock_in['rackno'] . "</th>";
            echo "<th>" . $stock_in['docketnumber'] . "</th>";
            echo "<th>" . $stock_in['manufacturingdate'] . "</th>";
            echo "<th>" . $stock_in['pickuprequestdate'] . "</th>";
            echo "<th>" . $stock_in['employee_id'] . "</th>";
            echo "<th>" . $stock_in['eng_id'] . "</th>";
            echo "<th>" . $stock_in['siteid'] . "</th>";
            echo "<th>" . $stock_in['docketdate'] . "</th>";
            echo "<th>" . $stock_in['remarks'] . "</th>";
            echo "<th>" . $stock_in['userid'] . "</th>";
            echo "<th>" . $stock_in['cus_id'] . "</th>";
            echo "<th>" . $stock_in['inserteddate'] . "</th>";
            echo "</tr>";
            foreach ($rows as $row) {
                echo "<tr>";
                echo "<td>";
                echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deletestockin(" . $row["stockin_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
                echo "&nbsp;";
                echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='savestockin(" . $row["stockin_id"] . ")'>" . $optionsIcons['save'] . "</a>";
                echo "</td>";
                echo "<td>" . $row['serialno'] . "</td>";
                echo "<td>";
                echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db);
                echo "<br/>";
                $idofcustomer = getName('projects', 'cus_id', 'project_id', $row['project_id'], $db);
                $customerid = getName('customerinfo', 'cus_id', 'cus_id', $idofcustomer, $db);
                echo "</td>";
                echo "<td>" . $row['productid'] . "</td>";
                echo "<td>" . $row['description'] . "</td>";
                echo "<td>" . $row['revisionstate'] . "</td>";
                echo "<td>" . getName('shiptype', 'typename', 'shiptype_id', $row['shiptype'], $db) . "</td>";
                echo "<td>" . $row['in_quantity'] . "</td>";
                echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
                echo "<td>" . $row['invoicenumber'] . "</td>";
                echo "<td>" . $row['shipid'] . "</td>";
                echo "<td>" . $row['mawb'] . "</td>";
                echo "<td>" . $row['hawb'] . "</td>";
                echo "<td>" . $row['receiveddate'] . "</td>";
                echo "<td>" . $row['shipfrom'] . "</td>";
                echo "<td>" . $row['boxno'] . "</td>";
                echo "<td>" . $row['rma'] . "</td>";
                echo "<td>" . getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouse_id'], $db) . "</td>";
                echo "<td>" . $row['rackno'] . "</td>";
                echo "<td>" . $row['docketnumber'] . "</td>";
                echo "<td>" . $row['manufacturingdate'] . "</td>";
                echo "<td>" . $row['pickuprequestdate'] . "</td>";
                echo "<td>" . getName('employee', 'employeename', 'employee_id', $row['employee_id'], $db) . "</td>";
                echo "<td>" . getName('engineerinfo', 'engname', 'eng_id', $row['eng_id'], $db) . "</td>";
                echo "<td>" . $row['siteid'] . "</td>";
                echo "<td>" . $row['docketdate'] . "</td>";
                echo "<td>" . $row['remarks'] . "</td>";
                echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
                echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
                echo "<td>" . $row['inserteddate'] . "</td>";
                echo "</tr>";
            }
            echo "<table>";
}
if ($_REQUEST['action'] == 'modifySO') {
    $soid = $_GET['soid'];
    $session_id = session_id();
    $sess_userID = $_SESSION['user']['id'];

    $query = "UPDATE stockout SET session_id = '" . $sess_userID . "', junkentry = '1' WHERE stockout_id = '" . $soid . "' AND session_id = '" . $session_id . "' ";
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    $rows = selectAllWhereAA('stockout', 'session_id', $session_id, $db);
    //var_dump($rows);
    echo "<table class=\"form-inline row-fluid table table-striped table-bordered\">";
    echo "<tr>";
    echo "<th>" . $optionsIcons['option'] . "</th>";
    echo "<th>" . $stock_out['serialno'] . "</th>";
    echo "<th>" . $stock_out['productid'] . "</th>";
    echo "<th>" . $stock_out['boxno'] . "</th>";
    echo "<th>" . $stock_out['description'] . "</th>";
    echo "<th>" . $stock_out['eng_id'] . "</th>";
    echo "<th>" . $stock_out['responsetype'] . "</th>";
    echo "<th>" . $stock_out['revisionstate'] . "</th>";
    echo "<th>" . $stock_out['challannumber'] . "</th>";
    echo "<th>" . $stock_out['out_quantity'] . "</th>";
    echo "<th>" . $stock_out['uom'] . "</th>";
    echo "<th>" . $stock_out['requestnumber'] . "</th>";
    echo "<th>" . $stock_out['requestedby'] . "</th>";
    echo "<th>" . $stock_out['siteid'] . "</th>";
    echo "<th>" . $stock_out['project_id'] . "</th>";
    echo "<th>" . $stock_out['requesttime'] . "</th>";
    echo "<th>" . $stock_out['deliverytime'] . "</th>";
    echo "<th>" . $stock_out['receivedtime'] . "</th>";
    echo "<th>" . $stock_out['sla'] . "</th>";
    echo "<th>" . $stock_out['receivername'] . "</th>";
    echo "<th>" . $stock_out['cellnumber'] . "</th>";
    echo "<th>" . $stock_out['warehouseid'] . "</th>";
    echo "<th>" . $stock_out['transportername'] . "</th>";
    echo "<th>" . $stock_out['employee_id'] . "</th>";
    echo "<th>" . $stock_out['remarks'] . "</th>";
    echo "<th>" . $stock_out['user_id'] . "</th>";
    echo "<th>" . $stock_out['cus_id'] . "</th>";
    echo "<th>" . $stock_out['inserteddate'] . "</th>";
    echo "</tr>";
    foreach ($rows as $row) {
        echo "<tr>";
        echo "<td>";
        echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deletestockout(" . $row["stockout_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
        echo "&nbsp;";
        echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='savestockout(" . $row["stockout_id"] . ")'>" . $optionsIcons['save'] . "</a>";
        echo "</td>";
        echo "<td>" . $row['serialno'] . "</td>";
        echo "<td>" . $row['productid'] . "</td>";
        echo "<td>" . $row['boxno'] . "</td>";
        echo "<td>" . $row['description'] . "</td>";
        echo "<td>" . getName('engineerinfo', 'engname', 'eng_id', $row['eng_id'], $db) . "</td>";
        echo "<td>" . getName('responsetype', 'uniquename', 'responsetype_id', $row['response_type_id'], $db) . "</td>";
        echo "<td>" . $row['revisionstate'] . "</td>";
        echo "<td>" . $row['challannumber'] . "</td>";
        echo "<td>" . $row['out_quantity'] . "</td>";
        echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
        echo "<td>" . $row['requestnumber'] . "</td>";
        echo "<td>" . $row['requestedby'] . "</td>";
        echo "<td>" . $row['siteid'] . "</td>";
        echo "<td>" . getName('projects', 'projectname', 'project_id', $row['project_id'], $db) . "</td>";
        echo "<td>" . $row['requesttime'] . "</td>";
        echo "<td>" . $row['deliverytime'] . "</td>";
        echo "<td>" . $row['receivedtime'] . "</td>";
        echo "<td>" . $row['sla'] . "</td>";
        echo "<td>" . $row['receivername'] . "</td>";
        echo "<td>" . $row['cellnumber'] . "</td>";
        echo "<td>" . getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouseid'], $db) . "</td>";
        echo "<td>" . $row['transportername'] . "</td>";
        echo "<td>" . getName('employee', 'employeename', 'employee_id', $row['employee_id'], $db) . "</td>";
        echo "<td>" . $row['remarks'] . "</td>";
        echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
        echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
        echo "<td>" . $row['inserteddate'] . "</td>";
        echo "</tr>";
    }
    echo "<table>";
    $sess_cusID = $_SESSION['user']['cus_id'];    
    $queryReturn = "INSERT INTO returnnote ( stockout_id, backstatus, cus_id, inserteddate) VALUES ( :stockout_id, :backstatus, :cus_id, :inserteddate)";
    $query_params_return = array(
        ':stockout_id'      => $soid,
        ':backstatus'       => 0,
        ':cus_id'           => $sess_cusID,
        ':inserteddate'     => date('Y-m-d H:i:s')
    );
    try {
        $stmt1 = $db->prepare($queryReturn);
        $result = $stmt1->execute($query_params_return);
        var_dump($stmt1);
    } catch (PDOException $ex) {
        die("Failed to run query: ". $ex->getMessage());
    }
}
if ($_REQUEST['action'] == 'modifyReturn') {
    $faulties_id = $_GET['faulties_id'];
    $session_id = session_id();
    $sess_cusID = $_SESSION['user']['id'];

    $query = "UPDATE faulties SET session_id = '" . $sess_cusID . "', junkentry = '1' WHERE faulties_id = '" . $faulties_id . "' AND session_id = '" . $session_id . "' ";
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }

    if ($result) {
        $session_id = session_id();
        $rows = selectAllWhereAA('faulties', 'session_id', $session_id, $db);

        echo "<table class=\"row-fluid table table-striped table-bordered\">";
        echo "<tr>";
        echo "<th>" . $optionsIcons['optionIcon'] . "</th>";
        echo "<th>" . $faulties['serialno'] . "</th>";
        echo "<th>" . $faulties['project_id'] . "</th>";
        echo "<th>" . $faulties['rma'] . "</th>";
        echo "<th>" . $faulties['pickuprequestdate'] . "</th>";
        echo "<th>" . $faulties['physicallyreceivedate'] . "</th>";
        echo "<th>" . $faulties['productid'] . "</th>";
        echo "<th>" . $faulties['description'] . "</th>";
        echo "<th>" . $faulties['revisionstate'] . "</th>";
        echo "<th>" . $faulties['boxno'] . "</th>";
        echo "<th>" . $faulties['uom'] . "</th>";
        echo "<th>" . $faulties['return_quantity'] . "</th>";
        echo "<th>" . $faulties['manufacturingdate'] . "</th>";
        echo "<th>" . $faulties['faultiesstatus'] . "</th>";
        echo "<th>" . $faulties['siteid'] . "</th>";
        echo "<th>" . $faulties['warehouseid'] . "</th>";
        echo "<th>" . $faulties['employeeid'] . "</th>";
        echo "<th>" . $faulties['docketdate'] . "</th>";
        echo "<th>" . $faulties['return_docketnumber'] . "</th>";
        echo "<th>" . $faulties['remarks'] . "</th>";
        echo "<th>" . $faulties['userid'] . "</th>";
        echo "<th>" . $customer_info['cusname'] . "</th>";
        echo "<th>" . $faulties['inserteddate'] . "</th>";
        echo "</tr>";
        foreach ($rows as $row) {
            echo "<tr>";
            echo "<td>";
            echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deletereturn(" . $row["faulties_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
            echo "&nbsp;";
            echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='savereturn(" . $row["faulties_id"] . ")'>" . $optionsIcons['save'] . "</a>";
            echo "</td>";
            echo "<td>" . $row['serialno'] . "</td>";
            echo "<td>";
            echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db);
            echo "<br/>";
            $idofcustomer = getName('projects', 'cus_id', 'project_id', $row['project_id'], $db);
            $customerid = getName('customerinfo', 'cus_id', 'cus_id', $idofcustomer, $db);
            echo "</td>";
            echo "<td>" . $row['rma'] . "</td>";
            echo "<td>" . $row['pickuprequestdate'] . "</td>";
            echo "<td>" . $row['physicallyreceivedate'] . "</td>";
            echo "<td>" . $row['productid'] . "</td>";
            echo "<td>" . $row['description'] . "</td>";
            echo "<td>" . $row['revisionstate'] . "</td>";
            echo "<td>" . $row['boxno'] . "</td>";
            echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
            echo "<td>" . $row['return_quantity'] . "</td>";
            echo "<td>" . $row['manufacturingdate'] . "</td>";
            echo "<td>" . getName('faultystatus', 'statusname', 'status_id', $row['faultiesstatus'], $db) . "</td>";
            echo "<td>" . $row['siteid'] . "</td>";
            echo "<td>" . getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouseid'], $db) . "</td>";
            echo "<td>" . getName('employee', 'employeename', 'employee_id', $row['employeeid'], $db) . "</td>";
            echo "<td>" . $row['docketdate'] . "</td>";
            echo "<td>" . $row['faulties_docketnumber'] . "</td>";
            echo "<td>" . $row['remarks'] . "</td>";
            echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
            echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
            echo "<td>" . $row['inserteddate'] . "</td>";
            echo "</tr>";
        }
        echo "<table>";
    }
}
if ($_REQUEST['action'] == 'modifyExport') {
    $faulty_export_id = $_GET['faulty_export_id'];
    $session_id = session_id();
    $sess_cusID = $_SESSION['user']['id'];

    $query = "UPDATE faulty_export SET session_id = '" . $sess_cusID . "', junkentry = '1' WHERE faulty_export_id = '" . $faulty_export_id . "' AND session_id = '" . $session_id . "' ";
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    $session_id = session_id();
    $rows = selectAllWhereAA('faulty_export', 'session_id', $session_id, $db);

    echo "<table class=\"row-fluid table table-striped table-bordered\">";
        echo "<tr>";
            echo "<th>" . $optionsIcons['optionIcon'] . "</th>";
            echo "<th>" . $faulty_export['serialno'] . "</th>";
            echo "<th>" . $faulty_export['project_id'] . "</th>";
            echo "<th>" . $faulty_export['productid'] . "</th>";
            echo "<th>" . $faulty_export['description'] . "</th>";
            echo "<th>" . $faulty_export['revisionstate'] . "</th>";
            echo "<th>" . $faulty_export['boxno'] . "</th>";
            echo "<th>" . $faulty_export['uom'] . "</th>";
            echo "<th>" . $faulty_export['faulty_export_quantity'] . "</th>";
            echo "<th>" . $faulty_export['handedoverto'] . "</th>";
            echo "<th>" . $faulty_export['manufacturingdate'] . "</th>";
            echo "<th>" . $faulty_export['faultydocketnumber'] . "</th>";
            echo "<th>" . $faulty_export['docketdate'] . "</th>";
            echo "<th>" . $faulty_export['siteid'] . "</th>";
            echo "<th>" . $faulty_export['warehouse_id'] . "</th>";
            echo "<th>" . $faulty_export['wh_rma'] . "</th>";
            echo "<th>" . $faulty_export['bd_rma'] . "</th>";
            echo "<th>" . $faulty_export['export_rma'] . "</th>";
            echo "<th>" . $faulty_export['rr_invoiceno'] . "</th>";
            echo "<th>" . $faulty_export['rr_date'] . "</th>";
            echo "<th>" . $faulty_export['rr_mawb'] . "</th>";
            echo "<th>" . $faulty_export['rr_awb'] . "</th>";
            echo "<th>" . $faulty_export['remarks'] . "</th>";
            echo "<th>" . $faulty_export['userid'] . "</th>";
            echo "<th>" . $customer_info['cusname'] . "</th>";
            echo "<th>" . $faulty_export['inserteddate'] . "</th>";
        echo "</tr>";
        foreach ($rows as $row) {
            echo "<tr>";
            echo "<td>";
            echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deleteexport(" . $row["faulty_export_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
            echo "&nbsp;";
            echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='saverexport(" . $row["faulty_export_id"] . ")'>" . $optionsIcons['save'] . "</a>";
            echo "</td>";
            echo "<td>" . $row['serialno'] . "</td>";
            echo "<td>";
            echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db);
            echo "<br/>";
            $idofcustomer = getName('projects', 'cus_id', 'project_id', $row['project_id'], $db);
            $customerid = getName('customerinfo', 'cus_id', 'cus_id', $idofcustomer, $db);
            echo "</td>";
            echo "<td>" . $row['productid'] . "</td>";
            echo "<td>" . $row['description'] . "</td>";
            echo "<td>" . $row['revisionstate'] . "</td>";
            echo "<td>" . $row['boxno'] . "</td>";
            echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
            echo "<td>" . $row['faulty_export_quantity'] . "</td>";
            echo "<td>" . $row['handedoverto'] . "</td>";
            echo "<td>" . $row['manufacturingdate'] . "</td>";
            echo "<td>" . $row['faultydocketnumber'] . "</td>";
            echo "<td>" . $row['docketdate'] . "</td>";
            echo "<td>" . $row['siteid'] . "</td>";
            echo "<td>" . getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouse_id'], $db) . "</td>";
            echo "<td>" . $row['wh_rma'] . "</td>";
            echo "<td>" . $row['bd_rma'] . "</td>";
            echo "<td>" . $row['export_rma'] . "</td>";
            echo "<td>" . $row['rr_invoiceno'] . "</td>";
            echo "<td>" . $row['rr_date'] . "</td>";
            echo "<td>" . $row['rr_mawb'] . "</td>";
            echo "<td>" . $row['rr_awb'] . "</td>";
            echo "<td>" . $row['remarks'] . "</td>";
            echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
            echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
            echo '<input type="hidden" name="session_id" value="' . session_id() . '" />';
            echo '<input type="hidden" name="junkentry" value="0" />';
            echo "<td>" . $row['inserteddate'] . "</td>";
            echo "</tr>";
        }
        echo "<table>";
}
if ($_REQUEST['action'] == 'modifyReturnNote') {
    $note_id = $_GET['note_id'];
    $session_id = session_id();
    $sess_cusID = $_SESSION['user']['id'];

    $query = "UPDATE returnnote SET backstatus = '1' WHERE note_id = '" . $note_id . "' ";
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    $sess_cusID = $_SESSION['user']['cus_id'];
    $rows = pickReturnStatus($sess_cusID, $db);

    echo "<table id=\"stockinhanddiv\" class=\"row-fluid table table-striped table-bordered\">";
    echo "<tr>";
        echo "<th>". $stock_out['requestnumber'] ."</th>";
        echo "<th>" . $stock_in['serialno'] . "</th>";
        echo "<th>" . $stock_in['productid'] . "</th>";
        echo "<th>" . $stock_out['siteid'] . "</th>";
        echo "<th>" . $stock_out['deliverytime'] . "</th>";
        echo "<th>" . $stock_out['out_quantity'] . "</th>";
        echo "<th>" . $stock_out['uom'] . "</th>";
        echo "<th>" . $stock_out['stockout_id'] . "</th>";
        echo "<th>" . $stock_in['inserteddate'] . "</th>";
        echo "<th>" . "Update as Received" . "</th>";
    echo "</tr>";
    foreach ($rows as $row) {
        echo "<tr>";
        echo "<td>". $row['requestnumber'] ."</td>";
        echo "<td>" . $row['serialno'] . "</td>";
        echo "<td>" . $row['productid'] . "</td>";
        echo "<td>" . $row['siteid'] . "</td>";
        echo "<td>" . $row['deliverytime'] . "</td>";
        echo "<td>" . $row['out_quantity'] . "</td>";
        echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
        echo "<td>" . $row['stockout_id'] . "</td>";
        echo "<td>" . $row['inserteddate'] . "</td>";
        echo "<td>" . "<a href='javascript:void(0)' class='btn btn-success btn-small' onclick='receivedok(" . $row['note_id'] . ")'><i class='icon-ok icon-white'></i>&nbsp; Tick</a>" . "</td>";
        echo "</tr>";
    }
    echo "<table>";
}


if ($_REQUEST['action'] == 'ModifyStockout') {
            $stockout_id    = $_POST['stockout_id'];
            $challannumber  = $_POST['challannumber'];
            $siteid         = $_POST['siteid'];
            $deliverytime   = $_POST['deliverytime'];
            $receivername   = $_POST['receivername'];
            $cellnumber     = $_POST['cellnumber'];
            $remarks        = $_POST['remarks'];

    $query = "UPDATE `stockout` SET `challannumber`='".$challannumber."',`siteid`='".$siteid."',`deliverytime`='".$deliverytime."',`receivername`='".$receivername."',`cellnumber`='".$cellnumber."',`remarks`='".$remarks."' WHERE `stockout_id`='".$stockout_id."' LIMIT 1";
    
    //var_dump($query);
    
    try {
        $stmt = $db->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
        $result = $stmt->execute();
    } catch(PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
}

if ($_REQUEST['action'] == 'modifyBugReport') {
    $reportid = $_GET['reportid'];
    $query = "UPDATE bugreport SET bugpointer = '1' WHERE reportid = '" . $reportid . "' ";
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    
    $rows = selectAllBug(DESC, "reportid", "bugreport", $db);
    echo "<h5>Bug Reports</h5>";
    echo "<table id=\"bugTable\" class=\"row-fluid table table-striped table-bordered\">";
        echo "<tr>";
            echo "<th>";
                echo "&nbsp;";
            echo "</th>";
            echo "<th>";
                echo $bugreport['title'];
            echo "</th>";
            echo "<th>";
                echo $bugreport['description'];
            echo "</th>";
            echo "<th>";
                echo $bugreport['userid'];
            echo "</th>";
            echo "<th>";
                echo $bugreport['inserteddate'];
            echo "</th>";
        echo "</tr>";
        foreach ($rows as $row) {
            echo "<tr>";
                echo "<td>";
                    echo "<a href='javascript:void(0)' onclick='okayBoss($row[reportid])'><i class='icon-ok'></i></a>";
                echo "</td>";
                echo "<td>";
                    echo $row['title'];
                echo "</td>";
                echo "<td>";
                    echo $row['description'];
                echo "</td>";
                echo "<td>";
                    echo getName('wms_users', 'username', 'id', $row['userid'], $db);
                echo "</td>";
                echo "<td>";
                    echo $row['inserteddate'];
                echo "</td>";
            echo "</tr>";
        }
    echo "<table>";
}
//if ($_REQUEST['action'] == 'modifyExport') {
//    $faulty_export_id = $_GET['faulty_export_id'];
//    $session_id = session_id();
//    $sess_cusID = $_SESSION['user']['id'];
//
//    $query = "UPDATE faulty_export SET session_id = '" . $sess_cusID . "', junkentry = '1' WHERE faulty_export_id = '" . $faulty_export_id . "' AND session_id = '" . $session_id . "' ";
//    try {
//        $stmt = $db->prepare($query);
//        $result = $stmt->execute($query_params);
//    } catch (PDOException $ex) {
//        die("Failed to run query: " . $ex->getMessage());
//    }
//    $session_id = session_id();
//    $rows = selectAllWhereAA('faulty_export', 'session_id', $session_id, $db);
//
//    echo "<table class=\"row-fluid table table-striped table-bordered\">";
//        echo "<tr>";
//            echo "<th>" . $optionsIcons['optionIcon'] . "</th>";
//            echo "<th>" . $faulty_export['serialno'] . "</th>";
//            echo "<th>" . $faulty_export['project_id'] . "</th>";
//            echo "<th>" . $faulty_export['productid'] . "</th>";
//            echo "<th>" . $faulty_export['description'] . "</th>";
//            echo "<th>" . $faulty_export['revisionstate'] . "</th>";
//            echo "<th>" . $faulty_export['boxno'] . "</th>";
//            echo "<th>" . $faulty_export['uom'] . "</th>";
//            echo "<th>" . $faulty_export['faulty_export_quantity'] . "</th>";
//            echo "<th>" . $faulty_export['handedoverto'] . "</th>";
//            echo "<th>" . $faulty_export['manufacturingdate'] . "</th>";
//            echo "<th>" . $faulty_export['faultydocketnumber'] . "</th>";
//            echo "<th>" . $faulty_export['docketdate'] . "</th>";
//            echo "<th>" . $faulty_export['siteid'] . "</th>";
//            echo "<th>" . $faulty_export['warehouse_id'] . "</th>";
//            echo "<th>" . $faulty_export['wh_rma'] . "</th>";
//            echo "<th>" . $faulty_export['rr_rma'] . "</th>";
//            echo "<th>" . $faulty_export['export_rma'] . "</th>";
//            echo "<th>" . $faulty_export['rr_invoiceno'] . "</th>";
//            echo "<th>" . $faulty_export['rr_date'] . "</th>";
//            echo "<th>" . $faulty_export['rr_mawb'] . "</th>";
//            echo "<th>" . $faulty_export['rr_awb'] . "</th>";
//            echo "<th>" . $faulty_export['remarks'] . "</th>";
//            echo "<th>" . $faulty_export['userid'] . "</th>";
//            echo "<th>" . $customer_info['cusname'] . "</th>";
//            echo "<th>" . $faulty_export['inserteddate'] . "</th>";
//        echo "</tr>";
//        foreach ($rows as $row) {
//            echo "<tr>";
//            echo "<td>";
//            echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deleteexport(" . $row["faulty_export_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
//            echo "&nbsp;";
//            echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='saverexport(" . $row["faulty_export_id"] . ")'>" . $optionsIcons['save'] . "</a>";
//            echo "</td>";
//            echo "<td>" . $row['serialno'] . "</td>";
//            echo "<td>";
//            echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db);
//            echo "<br/>";
//            $idofcustomer = getName('projects', 'cus_id', 'project_id', $row['project_id'], $db);
//            $customerid = getName('customerinfo', 'cus_id', 'cus_id', $idofcustomer, $db);
//            echo "</td>";
//            echo "<td>" . $row['productid'] . "</td>";
//            echo "<td>" . $row['description'] . "</td>";
//            echo "<td>" . $row['revisionstate'] . "</td>";
//            echo "<td>" . $row['boxno'] . "</td>";
//            echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
//            echo "<td>" . $row['faulty_export_quantity'] . "</td>";
//            echo "<td>" . $row['handedoverto'] . "</td>";
//            echo "<td>" . $row['manufacturingdate'] . "</td>";
//            echo "<td>" . $row['faultydocketnumber'] . "</td>";
//            echo "<td>" . $row['docketdate'] . "</td>";
//            echo "<td>" . $row['siteid'] . "</td>";
//            echo "<td>" . getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouse_id'], $db) . "</td>";
//            echo "<td>" . $row['wh_rma'] . "</td>";
//            echo "<td>" . $row['rr_rma'] . "</td>";
//            echo "<td>" . $row['export_rma'] . "</td>";
//            echo "<td>" . $row['rr_invoiceno'] . "</td>";
//            echo "<td>" . $row['rr_date'] . "</td>";
//            echo "<td>" . $row['rr_mawb'] . "</td>";
//            echo "<td>" . $row['rr_awb'] . "</td>";
//            echo "<td>" . $row['remarks'] . "</td>";
//            echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
//            echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
//            echo '<input type="hidden" name="session_id" value="' . session_id() . '" />';
//            echo '<input type="hidden" name="junkentry" value="0" />';
//            echo "<td>" . $row['inserteddate'] . "</td>";
//            echo "</tr>";
//        }
//    echo "<table>";
//}



if ($_REQUEST['action'] == 'modifyReturnNote') {
    $note_id = $_GET['note_id'];
    $session_id = session_id();
    $sess_cusID = $_SESSION['user']['id'];

    $query = "UPDATE returnnote SET backstatus = '1' WHERE note_id = '" . $note_id . "' ";
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    $sess_cusID = $_SESSION['user']['cus_id'];
    $rows = pickReturnStatus($sess_cusID, $db);

    echo "<table id=\"show\" class=\"form-inline row-fluid table table-striped table-bordered\">";
        echo "<tr>";
            echo "<th>". $stock_out['requestnumber'] ."</th>";
            echo "<th>". "Physically Received" ."</th>";
            echo "<th>". $return_note['pickupreceiveddate'] ."</th>";
            echo "<th>". $return_note['save'] ."</th>";
            echo "<th>". $stock_in['serialno'] ."</th>";
            echo "<th>". $stock_in['productid'] ."</th>";
            echo "<th>". $stock_out['siteid'] ."</th>";
            echo "<th>". $stock_out['receivedtime'] ."</th>";
            echo "<th>". $stock_out['out_quantity'] ."</th>";
            echo "<th>". $stock_out['uom'] ."</th>";
            echo "<th>". $stock_out['stockout_id'] ."</th>";
            echo "<th>". $stock_in['inserteddate'] ."</th>";
        echo "</tr>";
        //echo "<form class=\"form-horizontal\" action=\"addPickupRequestDate\" method=\"post\" id=\"addPickupRequestDate\">";
    foreach ($rows as $row) {
        echo "<tr>";
            echo "<td>". $row['requestnumber'] ."</td>";
            echo "<td>". "<a href='javascript:void(0)' class='btn btn-success btn-small' onclick='receivedok(".$row['note_id'].")'><i class='icon-ok icon-white'></i>&nbsp; Tick</a>" ."</td>";
            echo "<td>";
                echo '<input type="text" id="pickuprequestdate_'.$row['note_id'].'" class="span12" name="pickuprequestdate" value="'.$row['pickuprequestdate'].'" />';
                echo '<input type="hidden" id="note_id_'.$row['note_id'].'" name="note_id" value="'.$row['note_id'].'" />';
            echo "</td>";
            echo "<td>";
                echo "<a href='javascript:void(0)' class='btn btn-primary btn-small' onclick='updatepickuprequestdate(".$row['note_id'].")'>Save</a>";
            echo "</td>";
            echo "<td>". $row['serialno'] ."</td>";
            echo "<td>". $row['productid'] ."</td>";
            echo "<td>". $row['siteid'] ."</td>";
            echo "<td>". $row['receivedtime'] ."</td>";
            echo "<td>". $row['out_quantity'] ."</td>";
            echo "<td>". getName('uom', 'measurement', 'uom_id', $row['uom'], $db) ."</td>";
            echo "<td>". $row['stockout_id'] ."</td>";
            echo "<td>". $row['inserteddate'] ."</td>";
        echo "</tr>";
    }
    //echo "</form>";
    echo "<table>";
}



if ($_REQUEST['action'] == 'modifyStc') {
    $stc_id = $_GET['stc_id'];
    $session_id = session_id();
    $sess_cusID = $_SESSION['user']['id'];

    $query = "UPDATE screeningcenter SET session_id = '" . $sess_cusID . "', junkentry = '1' WHERE stc_id = '" . $stc_id . "' AND session_id = '" . $session_id . "' ";
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    
    $session_id = session_id();
    $rows = selectAllWhereAA('screeningcenter', 'session_id', $session_id, $db);

    echo "<table class=\"row-fluid table table-striped table-bordered\">";
    echo "<tr>";
        echo "<th>" . $optionsIcons['optionIcon'] . "</th>";
        echo "<th>" . $stc['serialno'] . "</th>";
        echo "<th>" . $stc['faulties_id'] . "</th>";
        echo "<th>" . $stc['wh_stc_no'] . "</th>";
        echo "<th>" . $stc['cus_stc_no'] . "</th>";
        echo "<th>" . $stc['report'] . "</th>";
        echo "<th>" . $faulty_export['userid'] . "</th>";
        echo "<th>" . $customer_info['cusname'] . "</th>";
        echo "<th>" . $faulty_export['inserteddate'] . "</th>";
    echo "</tr>";
    foreach ($rows as $row) {
        echo "<tr>";
        echo "<td>";
        echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deletestc(" . $row["stc_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
        echo "&nbsp;";
        echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='saverstc(" . $row["stc_id"] . ")'>" . $optionsIcons['save'] . "</a>";
        echo "</td>";
        echo "<td>" . $row['serialno'] . "</td>";
        echo "<td>" . $row['faulties_id'] . "</td>";
        echo "<td>" . $row['wh_stc_no'] . "</td>";
        echo "<td>" . $row['cus_stc_no'] . "</td>";
        echo "<td>" . $row['report'] . "</td>";            
        echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
        echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
        echo '<input type="hidden" name="session_id" value="' . session_id() . '" />';
        echo '<input type="hidden" name="junkentry" value="0" />';
        echo "<td>" . $row['inserteddate'] . "</td>";
        echo "</tr>";
    }
    echo "<table>";
}

if ($_REQUEST['action'] == 'ModifyStcenter') {
    $stc_id = $_POST['stc_id'];
    $cus_stc_no = $_POST['cus_stc_no'];
    $report = $_POST['report'];

    $query = "UPDATE screeningcenter SET cus_stc_no = '" . $cus_stc_no . "', report = '" . $report . "' WHERE stc_id = '" . $stc_id . "'";
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    
    $sess_userID = $_SESSION['user']['id'];
    $rows = modifyStc($sess_userID, $db);

    echo "<table class=\"row-fluid table table-striped table-bordered\">";
    echo "<tr>";
        echo "<th>" . $optionsIcons['optionIcon'] . "</th>";
        echo "<th>" . $stc['serialno'] . "</th>";
        echo "<th>" . $stc['faulties_id'] . "</th>";
        echo "<th>" . $stc['wh_stc_no'] . "</th>";
        echo "<th>" . $stc['cus_stc_no'] . "</th>";
        echo "<th>" . $stc['report'] . "</th>";
        echo "<th>" . $faulty_export['userid'] . "</th>";
        echo "<th>" . $customer_info['cusname'] . "</th>";
        echo "<th>" . $faulty_export['inserteddate'] . "</th>";
    echo "</tr>";
    foreach ($rows as $row) {
        echo "<tr>";
        echo "<td>";
        echo "<a class='btn btn-danger btn-mini' href='javascript:void(0)' onclick='deletestc(" . $row["stc_id"] . ")'>" . $optionsIcons['delete'] . "</a>";
        echo "&nbsp;";
        echo "<a class='btn btn-success btn-mini' href='javascript:void(0)' onclick='saverstc(" . $row["stc_id"] . ")'>" . $optionsIcons['save'] . "</a>";
        echo "</td>";
        echo "<td>" . $row['serialno'] . "</td>";
        echo "<td>" . $row['faulties_id'] . "</td>";
        echo "<td>" . $row['wh_stc_no'] . "</td>";
        echo "<td>" . $row['cus_stc_no'] . "</td>";
        echo "<td>" . $row['report'] . "</td>";            
        echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
        echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
        echo '<input type="hidden" name="session_id" value="' . session_id() . '" />';
        echo '<input type="hidden" name="junkentry" value="0" />';
        echo "<td>" . $row['inserteddate'] . "</td>";
        echo "</tr>";
    }
    echo "<table>";
}

if ($_REQUEST['action'] == 'addExportRMA') {
    $faulty_export_id = $_GET['faulty_export_id'];
    $sql = "SELECT * FROM faulty_export WHERE faulty_export_id = '".$faulty_export_id."'";
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    $rows = $stmt->fetchAll();
}
if($_REQUEST['action'] == 'addExportRMA') {
    $query = "UPDATE faulty_export SET wh_rma = '" . $wh_rma . "', bd_rma = '" . $bd_rma . "', export_rma = '" . $export_rma . "', rr_invoiceno = '" . $rr_invoiceno . "' WHERE faulty_export_id = '" . $faulty_export_id . "'";
    
    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    
    $rows = $stmt->fetchAll();
    
    echo "<br/>";
    echo "<table id='movementHistory' class='row-fluid table table-striped table-bordered'>";
        echo "<tr>";
            echo "<th>Option</th>";
            echo "<th>Warehouse RMA</th>";
            echo "<th>Breakdown RMA</th>";
            echo "<th>Export RMA</th>";
            echo "<th>Export Invoice</th>";
        echo "</tr>";
        
        foreach ($rows as $row) {
            echo "<tr>";
                echo "<td><a class='btn btn-primary' href='javascript:void(0)' onclick=\"addExportRMA('".$row['faulty_export_id']."'\")'>Edit</a></td>";
                echo "<td>". $row['wh_rma'] ."</td>";
                echo "<td>". $row['bd_rma'] ."</td>";
                echo "<td>". $row['export_rma'] ."</td>";
                echo "<td>". $row['rr_invoiceno'] ."</td>";
            echo "</tr>";
        }
    echo "</table>";
    
}

?>
